/**
 * used to format JSONObject
 * it will add \t before a new line, and add \n at the end of the lines.
 * 
 * 2016-10-23
 */
;
(function($) {
	$.extend({
		evalJSON : function(object) {
			return eval("(" + object + ")");
		},
	
		toJSONString : function(object) {
			return parseJSON(object, "");
		}
	});

	function parseJSON(object, before) {
		if (object === null)
			return 'null';

		var type = typeof object;
		if ('object' == type) {
			if (Array == object.constructor)
				type = 'array';
			else if (RegExp == object.constructor)
				type = 'regexp';
			else
				type = 'object';
		}
		switch (type) {
		case 'undefined':
		case 'unknown':
			return;
			break;
		case 'function':
		case 'boolean':
		case 'regexp':
			return object.toString();
			break;
		case 'number':
			return isFinite(object) ? object.toString() : 'null';
			break;
		case 'string':
			return '"' + object.replace(/(\\|\")/g, "\\$1").replace(/\n|\r|\t/g,
							function() {
								var a = arguments[0];
								return (a == '\n') ? '\\n' : (a == '\r') ? '\\r' : (a == '\t') ? '\\t' : "";
							}) + '"';
			break;
		case 'object':
			if (object === null)
				return 'null';
			var results = [];
			for ( var property in object) {
				var value = parseJSON(object[property], before + "\t");
				if (value !== undefined)
					results.push(before + parseJSON(property) + ':' + value);
			}
			return before + '{\n' + results.join(',\n') + "\n" + before + '}';
			break;
		case 'array':
			var results = [];
			for ( var i = 0; i < object.length; i++) {
				var value = parseJSON(object[i], before);
				if (value !== undefined)
					results.push(value);
			}
			return '[\n' + results.join(',\n') + ']';
			break;
		}
	}
})(jQuery);